package com.lemon.smartsafety.http.service;

import android.content.Context;
import android.util.Log;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.entity.bind.BindInfoExtVo;
import com.lemon.smartsafety.entity.common.CommonVo;
import com.lemon.smartsafety.entity.common.RoleVo;
import com.lemon.smartsafety.entity.user.ScoreInfoVo;
import com.lemon.smartsafety.entity.user.User;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * Created by Cooliean on 16/1/19.
 * 用户相关的网络请求方法
 */
public class UserServices extends BaseHttpServices {
    private static      LoggerHelper loggerHelper = new LoggerHelper(UserServices.class);
    public static final String       TAG          = "UserServices";

    public UserServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static UserServices init() {
        return new UserServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static UserServices init(Context context) {
        return new UserServices(context);
    }

    /**
     * 登录方法
     *
     * @param params
     */
    public void doLogin(LemonRequestParams params) {
        HandlerCallback<User> callback = new HandlerCallback<User>(UrlInfo.LOGIN) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.LOGIN);
        Log.v("serverUrl is ",serverUrl);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }


    /**
     * 获取角色
     */
    public void getRoleList() {
        LemonRequestParams params = new LemonRequestParams();
        HandlerCallback<List<RoleVo>> callback = new HandlerCallback<List<RoleVo>>(EventTag.TAG_ROLE) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.ROLE);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }


    /**
     * 注册
     */
    public void doRegister(LemonRequestParams params) {
        HandlerCallback<String> callback = new HandlerCallback<String>(EventTag.TAG_REGISTER_ACTION) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.REGISTER);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }


    /**
     * 我的Apps
     */
    public void getMyApps() {
        LemonRequestParams params = new LemonRequestParams();
        HandlerCallback<List<BindInfoExtVo>> callback = new HandlerCallback<List<BindInfoExtVo>>(EventTag.TAG_MY_APPS) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.MY_APP);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }


    /**
     * 我的未读公告
     */
    public void getMyUnReadNoticeCount() {
        LemonRequestParams params = new LemonRequestParams();
        params.put("has_read", "0");
        HandlerCallback<CommonVo> callback = new HandlerCallback<CommonVo>(EventTag.TAG_MY_UN_READ_NOTICE) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.MY_UN_READ_NOTICE);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }


    /**
     * 修改密码
     */
    public void doModifyPassword(LemonRequestParams params) {
        HandlerCallback<String> callback = new HandlerCallback<String>(EventTag.TAG_MODIFY_PASSWORD) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.MODIFY_PASSWORD);
        Log.i("serverUrl=",serverUrl);
        Log.i("params=",params.toString());

        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }



    /**
     * 我的积分
     */
    public void getMyScoreList() {
        LemonRequestParams params = new LemonRequestParams();
        HandlerCallback<ScoreInfoVo> callback = new HandlerCallback<ScoreInfoVo>(EventTag.TAG_MY_SCORE) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.MY_SCORE);
        OkHttpUtils.getInstance().post().tag(callback.getTag()).url(serverUrl).params(params).build().execute(callback);

    }
}
